﻿#pragma once

#include "MapObject.h"
#include <string>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include "../../rectangularvectors.h"
#include "../../tangible_filesystem.h"

namespace Client::MirObjects
{
    class CellInfo
    {
    public:
        short BackIndex = 0;
        int BackImage = 0;
        short MiddleIndex = 0;
        int MiddleImage = 0;
        short FrontIndex = 0;
        int FrontImage = 0;

        unsigned char DoorIndex = 0;
        unsigned char DoorOffset = 0;

        unsigned char FrontAnimationFrame = 0;
        unsigned char FrontAnimationTick = 0;

        unsigned char MiddleAnimationFrame = 0;
        unsigned char MiddleAnimationTick = 0;

        short TileAnimationImage = 0;
        short TileAnimationOffset = 0;
        unsigned char TileAnimationFrames = 0;

        unsigned char Light = 0;
        unsigned char Unknown = 0;
        std::vector<MapObject*> CellObjects;

        bool FishingCell = false;

        void AddObject(MapObject *ob);
        void RemoveObject(MapObject *ob);
        MapObject *FindObject(unsigned int ObjectID);
        void DrawObjects();

        void DrawDeadObjects();

        void Sort();
    };

    class MapReader
    {
    public:
        int Width = 0, Height = 0;
        std::vector<std::vector<CellInfo*>> MapCells;
    private:
        std::string FileName;
        std::vector<unsigned char> Bytes;

    public:
        MapReader(const std::string &FileName);

    private:
        void initiate();

        void LoadMapType0();

        void LoadMapType1();

        void LoadMapType2();

        void LoadMapType3();

        void LoadMapType4();

        void LoadMapType5();

        void LoadMapType6();

        void LoadMapType7();

        void LoadMapType100();

    };

}
